// Package _9__单词搜索 main
// @Title _9__单词搜索
// @Description
// @Author  == 琳琳也叫王木木 ==  2022-02-25 16:17
// @Create  2022-02-25 16:17
package main

// 对二维矩阵进行感染
func visited(board [][]byte, word string, i, j, n, m, target int) bool {
	if i < 0 || j < 0 || i >= n || j >= m || board[i][j] != word[target] {
		return false
	}
	if target == len(word)-1 {
		return true
	}
	temp := board[i][j]
	board[i][j] = 'X'

	res := visited(board, word, i-1, j, n, m, target+1) ||
		visited(board, word, i+1, j, n, m, target+1) ||
		visited(board, word, i, j-1, n, m, target+1) ||
		visited(board, word, i, j+1, n, m, target+1)
	board[i][j] = temp
	return res
}

func exist(board [][]byte, word string) bool {
	for i := 0; i < len(board); i++ {
		for j := 0; j < len(board[i]); j++ {
			if visited(board, word, i, j, len(board), len(board[i]), 0) {
				return true
			}
		}
	}
	return false
}

func main() {

}
